<template>
  <div>
    <el-dialog class="positionDialog" :title="this.ruleForm.id ? '修改' : '新增'" :visible="showDialog" width="98%"
      :before-close="handleClose" :modal="false" :close-on-click-modal="false">
      <div class="content">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
          <div class="title fir-title">
            <svg-icon class="svg-icon" icon-class="infoAdd" />
            <span>入库填报</span>
          </div>
          <div class="form">
            <el-form-item label="智慧卡号" prop="">
              <el-input v-model="ruleForm.cardNumber" placeholder="请输入智慧卡号" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="车牌号" prop="carName">
              <el-select style="width: 100%;" v-model="ruleForm.carName" filterable placeholder="请选择车牌号或输入关键词">
                <el-option v-for="item in carList" :key="item.value" :label="item.label" :value="item.label">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('carInfo')">新增</el-button>
            </el-form-item>
            <el-form-item label="司机姓名" prop="driverPhone">
              <el-select style="width: 100%;" v-model="ruleForm.driverPhone" filterable placeholder="请选择司机姓名或输入关键词"
                @change="handleDriverName">
                <el-option v-for="item, index in driverList" :key="item.value + index" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('driverInfo')">新增</el-button>
            </el-form-item>
            <el-form-item v-if="hasIdentifier('Inbound.field')" label="押车人" prop="">
              <el-select style="width: 100%;" v-model="ruleForm.personPhone" filterable placeholder="请选择押车人或输入关键词"
                @change="handleEscortPerson">
                <el-option v-for="item, index in escortPersonList" :key="item.value + index" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('betcarInfo')">新增</el-button>
            </el-form-item>
          </div>
          <div class="title">
            <span>仓库信息</span>
          </div>
          <div class="form">
            <el-form-item label="农场" prop="farmCode">
              <el-select style="width: 100%;" v-model="ruleForm.farmCode" filterable placeholder="请选择农场或输入关键词"
                @change="handleSelectTeam">
                <el-option v-for="item in farmList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="来自生产队" prop="sourceTeam">
              <el-select style="width: 100%;" v-model="ruleForm.sourceTeam" filterable placeholder="请选择生产队或输入关键词"
                @change="handleGetCropType">
                <!-- @change="" -->
                <el-option v-for="item in teamList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="hasIdentifier('Inbound.field')" label="来自地块号" prop="massifNumber">
              <el-select style="width: 100%;" v-model="ruleForm.massifNumber" filterable placeholder="请选择地块号或输入关键词"
                @change="setmassifName" :disabled="ruleForm.sourceTeam ? false : true">
                <el-option v-for="item, index in massifNumberList" :key="item.value + index" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="种类" prop="cropType">
              <el-select style="width: 100%;" v-model="ruleForm.cropType" filterable placeholder="请选择作物类型或输入关键词"
                @change="handleChangeCropType" @focus="handleInspect">
                <el-option v-for="item, index in cropinfoList" :key="item.label + index" :label="item.label"
                  :value="item.label">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="品质" prop="cropQuality">
              <el-select style="width: 100%;" v-model="ruleForm.cropQuality" filterable placeholder="请选择作物类型或输入关键词"
                :disabled="ruleForm.cropType ? false : true" @change="handleWarehouse">
                <el-option v-for="item in cropQualityList" :key="item.value" :label="item.label" :value="item.label">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="仓号" prop="warehouseNumber">
              <el-select style="width: 100%;" v-model="ruleForm.warehouseNumber" filterable placeholder="请选择仓号或输入关键词"
                :disabled="ruleForm.cropQuality ? false : true" @change="handleDuo">
                <el-option v-for="item in wareList" :key="item.value" :label="item.label" :value="item.label">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="垛号" prop="stampId">
              <el-select style="width: 100%;" v-model="ruleForm.stampId" filterable placeholder="请选择垛号或输入关键词"
                :disabled="ruleForm.warehouseNumber && duoList.length ? false : true">
                <el-option v-for="item in duoList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="作物品种" prop="cropVarieties">
              <el-select style="width: 100%;" v-model="ruleForm.cropVarieties" filterable placeholder="请选择作物品种或输入关键词"
                :disabled="ruleForm.cropType ? false : true">
                <el-option v-for="item in cropVarietiesList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('cropVariety')">新增</el-button>
            </el-form-item>
            <el-form-item label="类别" prop="categoryName">
              <el-select style="width: 100%;" v-model="ruleForm.categoryName" filterable placeholder="请选择类别或输入关键词">
                <el-option v-for="item in categoryList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('cropType')">新增</el-button>
            </el-form-item>
          </div>
          <div class="title">
            <span>过磅信息</span>
          </div>
          <div class="form">
            <el-form-item label="毛重(kg)" prop="gw">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.gw" placeholder="请输入毛重"
                @blur="handleGW" :disabled="ruleForm.cropType ? false : true"></el-input>
            </el-form-item>
            <el-form-item label="皮重(kg)" prop="">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.tare" placeholder="请输入皮重"
                @blur="handleTARE" :disabled="ruleForm.cropType ? false : true"></el-input>
            </el-form-item>
            <el-form-item label="净重(kg)" v-if="hasIdentifier('Inbound.field')" prop="">
              <el-input v-model="netWeight" placeholder="请输入净重" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="净重(kg)" v-if="!hasIdentifier('Inbound.field')" prop="">
              <el-input v-model="ruleForm.nw" placeholder="请输入净重" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="过毛时间" :prop="ruleForm.gw ? 'hairingTime' : 'hairingTime'">
              <el-date-picker style="width: 100%;" v-model="ruleForm.hairingTime" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="请选择过毛时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="过皮时间" :prop="ruleForm.tare ? 'peelingTime' : ''">
              <el-date-picker style="width: 100%;" v-model="ruleForm.peelingTime" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="请选择过皮时间">
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="title">
            <span>扦样质检信息</span>
          </div>
          <div class="form">
            <el-form-item label="含水量(%)">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.water"
                placeholder="请输入含水量(0-100)" :disabled="ruleForm.gw ? false : true"></el-input>
            </el-form-item>
            <el-form-item label="含油量(%)">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.yau"
                placeholder="当作物为油菜时请输入含油量(0-100)"
                :disabled="(ruleForm.gw && ruleForm.cropType == '油菜') ? false : true"></el-input>
            </el-form-item>
            <el-form-item label="面筋值(%)">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.glutenValue"
                placeholder="当作物为小麦时请输入面筋值(0-100)"
                :disabled="(ruleForm.gw && ruleForm.cropType == '小麦') ? false : true"></el-input>
            </el-form-item>
            <el-form-item v-if="hasIdentifier('Inbound.field')" label="扣水比例(%)" prop="">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.waterRatio" placeholder="请输入扣水比例"
                @input="handleWater" style="position: relative;"></el-input>
              <div class="error-message" style="position: absolute;bottom: -30px;">扣水重量：{{ waterWeight }} kg</div>
            </el-form-item>
            <el-form-item v-if="hasIdentifier('Inbound.field')" label="扣杂比例(%)" prop="">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.mixedRatio" placeholder="请输入扣杂比例"
                @input="handleMis" style="position: relative;"></el-input>
              <div class="error-message" style="position: absolute;bottom: -30px;">扣杂重量：{{ mixedWeight }} kg</div>
            </el-form-item>
            <el-form-item v-if="hasIdentifier('Inbound.field')" label="扣杂后净重(kg)" prop="" style="position: relative;">
              <el-input v-model="ruleForm.nw" placeholder="自动计算" :disabled="true"></el-input>
              <div class="error-message" style="position: absolute;bottom: -30px;">扣杂后净重 = 净重*（1-扣水比例-扣杂比例）</div>
            </el-form-item>
          </div>
          <div class="kongkong" style="width: 100%;height: 40px;"></div>
        </el-form>
        <!-- <div class="button-box">
          <div class="inStoragePCButton">空车写入</div>
          <div class="inStoragePCButton">满车写入</div>
        </div> -->
      </div>

      <div class="dialog-footer">
        <el-button class="submit" @click="handleSubmit">确 认</el-button>
        <el-button class="back" @click="handleClose">返 回</el-button>
      </div>
    </el-dialog>

    <!-- 新增车牌号 -->
    <CarInfo ref="CarInfo" :showDialog.sync="carInfo" @handleRefresh="handleRefreshList('carInfo')"></CarInfo>
    <!-- 司机信息 -->
    <DriverInfo ref="DriverInfo" :showDialog.sync="driverInfo" @handleRefresh="handleRefreshList('driverInfo')">
    </DriverInfo>
    <!-- 押车人信息 -->
    <BetcarInfo ref="BetcarInfo" :showDialog.sync="betcarInfo" @handleRefresh="handleRefreshList('betcarInfo')">
    </BetcarInfo>
    <!-- 种类 -->
    <CropInfo ref="CropInfo" :showDialog.sync="cropInfo" @handleRefresh="handleRefreshList('cropInfo')"></CropInfo>
    <!-- 作物品种 -->
    <CropVariety ref="CropVariety" :showDialog.sync="cropVariety" @handleRefresh="handleRefreshList('cropVariety')">
    </CropVariety>
    <!-- 作物类别 -->
    <CropType ref="CropType" :showDialog.sync="cropType" @handleRefresh="handleRefreshList('cropType')"></CropType>
    <!-- 水份扣重 -->
    <WaterStandard ref="WaterStandard" :showDialog.sync="waterStandard"
      @handleRefresh="handleRefreshList('waterStandard')">
    </WaterStandard>
    <!-- 扣杂标准 -->
    <ImpurityStandard ref="ImpurityStandard" :showDialog.sync="impurityStandard"
      @handleRefresh="handleRefreshList('impurityStandard')"></ImpurityStandard>
  </div>
</template>

<script>
import '../scss/style.scss'
import rules from '@/utils/rules'
import { Message } from 'element-ui'
import { filterSelect, formatDate } from '@/utils/methods'
import { getPlotUnitListApi } from '@/api/inStorage'
import { addApi, editApi, warehouseApi, getCropTypeApi, getduoApi, getQualityApi, getInfoApi } from '@/api/inCage'
import { selectApi, carinfoApi, driverInfoApi, cropTypeApi, categorySelectApi, escortPersonApi } from '@/api/select'
import CarInfo from '@/views/info/components/CarInfo/dialog/AddPopu.vue'
import DriverInfo from '@/views/info/components/DriverInfo/dialog/AddPopu.vue'
import BetcarInfo from '@/views/info/components/BetcarInfo/dialog/AddPopu.vue'
import CropInfo from '@/views/info/components/CropInfo/dialog/AddPopu.vue'
import CropVariety from '@/views/info/components/CropVariety/dialog/AddPopu.vue'
import CropType from '@/views/info/components/CropType/dialog/AddPopu.vue'
import WaterStandard from '@/views/info/components/WaterStandard/dialog/AddPopu.vue'
import ImpurityStandard from '@/views/info/components/ImpurityStandard/dialog/AddPopu.vue'
import { mapGetters } from 'vuex';
export default {
  props: ['showDialog'],
  components: {
    CarInfo,
    DriverInfo,
    BetcarInfo,
    CropInfo,
    CropVariety,
    CropType,
    WaterStandard,
    ImpurityStandard
  },
  data() {
    return {
      ruleForm: {
        cardNumber: '',
        carName: '',
        driverPhone: '',
        driverName: '',
        farmCode: '',
        teamCode: '',
        // 货物来源生产队
        sourceTeam: '',
        cropType: '',
        cropQuality: '',
        warehouseNumber: '',
        stampId: '',
        cropVarieties: '',
        categoryName: '',
        gw: '',
        tare: '',
        nw: '',
        hairingTime: '',
        peelingTime: '',
        water: '',
        yau: '',
        glutenValue: '',
        waterRatio: null,
        mixedRatio: null,
      },
      // 毛重-皮重=净重
      netWeight: '',
      waterWeight: 0,
      mixedWeight: 0,
      rules: rules,
      // 车牌号
      carList: [],
      // 司机
      driverList: [],
      // 押车人
      escortPersonList: [],
      // 地块号
      massifNumberList: [],
      // 农场
      farmList: [],
      // 生产队
      teamList: [],
      // 作物种类
      cropinfoList: [],
      // 作物品种
      cropVarietiesList: [],
      // 作物类别
      categoryList: [],
      // 品质
      cropQualityList: [],
      // 仓号
      wareList: [],
      // 垛号
      duoList: [],
      carInfo: false,
      driverInfo: false,
      betcarInfo: false,
      cropInfo: false,
      cropVariety: false,
      cropType: false,
      waterStandard: false,
      impurityStandard: false,
    };
  },
  computed: {
    ...mapGetters(['hasIdentifier']), // 映射 getters
  },
  methods: {
    handleClose() {
      this.$emit('update:showDialog', false)
      this.netWeight = ''
      this.ruleForm = {
        cardNumber: '',
        carName: '',
        driverPhone: '',
        driverName: '',
        farmCode: '',
        teamCode: '',
        // 货物来源生产队
        sourceTeam: '',
        cropType: '',
        cropQuality: '',
        warehouseNumber: '',
        stampId: '',
        cropVarieties: '',
        categoryName: '',
        gw: '',
        tare: '',
        nw: '',
        hairingTime: '',
        peelingTime: '',
        water: '',
        yau: '',
        glutenValue: '',
        waterRatio: null,
        mixedRatio: null,
      },
        this.$refs.ruleForm.resetFields();
    },
    // 获取填报人时间
    handleGetInfo() {
      this.ruleForm.hairingTime = formatDate(new Date())
      // this.ruleForm.peelingTime = formatDate(new Date())
    },
    // 回填
    async getInfo(id) {
      let { data } = await getInfoApi({ id })
      this.ruleForm = data
      this.handleGetSelect()
    },
    handleSubmit() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          if (this.ruleForm.id) {
            let { code } = await editApi(this.ruleForm)
            if (code == 0) {
              Message({
                message: '修改成功',
                type: 'success',
                duration: 3 * 1000
              })
            }
          } else {
            let { code } = await addApi({ ...this.ruleForm, type: '1', nwOne: this.netWeight })
            if (code == 0) {
              Message({
                message: '添加成功',
                type: 'success',
                duration: 3 * 1000
              })
            }
          }
          this.$emit('handleRefresh')
          this.$emit('handleUpdate')
          this.handleClose()
        } else {
          return false;
        }
      });
    },
    // 获取下拉框
    handleGetSelect() {
      Promise.all([
        carinfoApi(this.$farmCode),
        driverInfoApi(this.$farmCode),
        selectApi({ type: 'farm_type' }),
        categorySelectApi(),
        escortPersonApi(this.$farmCode),
      ]).then(resList => {
        this.carList = filterSelect(resList[0].data)
        this.driverList = resList[1].data
        if (this.$status != '0') {
          this.ruleForm.farmCode = this.$farmCode
          this.farmList = resList[2].data.dictItemList.filter(item => item.value == this.$farmCode)
          this.handleSelectTeam(this.$farmCode)
        } else {
          this.farmList = resList[2].data.dictItemList
        }
        this.categoryList = filterSelect(resList[3].data)
        this.escortPersonList = resList[4].data
        if (this.ruleForm.id) {
          this.handleCropTypeEdit(this.ruleForm.cropType)
          this.handleGW()
          this.handleTARE()
        }
        this.$nextTick(() => {
          this.$refs.ruleForm.clearValidate('cropQuality')
          this.$refs.ruleForm.clearValidate('warehouseNumber')
          this.$refs.ruleForm.clearValidate('stampId')
        })
      })
    },
    // 选择生产队
    async handleSelectTeam(e) {
      let i = this.farmList.findIndex(item => item.value == e)
      this.ruleForm.remarks = this.farmList[i].remarks
      let res = await selectApi({ type: e })
      // this.ruleForm.farmCode = this.$farmCode
      // if (this.$status == '2') {
      //   this.ruleForm.teamCode = this.$teamCode
      //   this.teamList = res.data.dictItemList.filter(item => item.value == this.$teamCode)
      // } else {
      this.teamList = res.data.dictItemList
      if (this.$status == '2') {
        this.ruleForm.teamCode = this.$teamCode
      }

      // }
      if (this.ruleForm.id) {
        this.handleGetCropTypeEdit()
      } else {
        this.handleGetCropType()
      }
      this.$nextTick(() => {
        this.$refs.ruleForm.clearValidate('teamCode')
        this.$refs.ruleForm.clearValidate('farmCode')
      })
      if (this.ruleForm.sourceTeam && this.ruleForm.id) {
        this.handleChangeMassifNumberEdit()
      }
    },
    // 选择地块号
    async handleChangeMassifNumber() {
      if (this.ruleForm.sourceTeam) {
        this.$set(this.ruleForm, 'massifNumber', '')
        this.massifNumberList = []
        this.$refs.ruleForm.clearValidate('massifNumber')
        let res = await getPlotUnitListApi({ teamId: this.ruleForm.sourceTeam })
        this.massifNumberList = res.data.map(item => {
          return {
            label: item.massifName,
            value: item.massifNumber
          }
        })
      }
    },
    // 选择地块号
    async handleChangeMassifNumberEdit() {
      if (this.ruleForm.sourceTeam) {
        this.$refs.ruleForm.clearValidate('massifNumber')
        let res = await getPlotUnitListApi({ teamId: this.ruleForm.sourceTeam })
        this.massifNumberList = res.data.map(item => {
          return {
            label: item.massifName,
            value: item.massifNumber
          }
        })
      }
    },
    setmassifName(e) {
      let i = this.massifNumberList.findIndex(item => item.value == e)
      this.ruleForm.massifName = this.massifNumberList[i].label
    },
    // 选择司机
    handleDriverName(e) {
      let i = this.driverList.findIndex(item => item.value == e)
      this.ruleForm.driverName = this.driverList[i].label
    },
    // 选择押车人 escortPersonList
    handleEscortPerson(e) {
      let i = this.escortPersonList.findIndex(item => item.value == e)
      this.ruleForm.personName = this.escortPersonList[i].label
    },
    // 根据生产队选择种类
    async handleGetCropType() {
      if (!this.ruleForm.farmCode || !this.ruleForm.teamCode) return
      this.handleChangeMassifNumber()
      let res = await getCropTypeApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode })
      this.cropinfoList = res.data
    },
    // 根据生产队选择种类  修改回填
    async handleGetCropTypeEdit() {
      let res = await getCropTypeApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode })
      this.cropinfoList = res.data
    },
    // 检验种类是否有值
    handleInspect() {
      // if (!this.cropinfoList.length) {
      //   Message({
      //     message: '暂无作物种类，请前往填报',
      //     type: 'warning',
      //     duration: 3 * 1000
      //   })
      // }
    },
    // 选择作物品种
    async handleChangeCropType(e) {
      this.ruleForm.cropQuality = ''
      this.ruleForm.warehouseNumber = ''
      this.ruleForm.stampId = ''
      if (!e) return
      Promise.all([
        getQualityApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.cropType }),
        cropTypeApi(e)
      ]).then(res => {
        this.cropQualityList = filterSelect(res[0].data)
        this.cropVarietiesList = filterSelect(res[1].data)
      })

    },
    // 选择作物品种 修改回填
    async handleCropTypeEdit(e) {
      Promise.all([
        getQualityApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.cropType }),
        cropTypeApi(e)
      ]).then(res => {
        this.cropQualityList = filterSelect(res[0].data)
        this.cropVarietiesList = filterSelect(res[1].data)
      })
      this.handlechangeWarehouseEdit()

    },
    // 获取仓号
    async handleWarehouse() {
      this.ruleForm.warehouseNumber = ''
      this.ruleForm.stampId = ''
      if (this.ruleForm.farmCode && this.ruleForm.teamCode && this.ruleForm.cropType && this.ruleForm.cropQuality) {
        let res = await warehouseApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.cropType, cropQuality: this.ruleForm.cropQuality })
        if (res.code == 0) {
          this.wareList = res.data
        } else {
          this.wareList = []
          this.ruleForm.warehouseNumber = ''
        }
      }
    },
    // 获取仓号 修改回填
    async handlechangeWarehouseEdit() {
      let res = await warehouseApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.cropType, cropQuality: this.ruleForm.cropQuality })
      if (res.code == 0) {
        this.wareList = res.data

      } else {
        this.wareList = []
        this.ruleForm.warehouseNumber = ''
      }
      this.handlechangeDuoEdit()
    },
    // 选择垛号
    async handleDuo() {
      this.ruleForm.stampId = ''
      this.ruleForm.warehouseId = this.wareList.find(item => item.label == this.ruleForm.warehouseNumber).value
      if (this.ruleForm.farmCode && this.ruleForm.teamCode && this.ruleForm.cropType && this.ruleForm.cropQuality && this.ruleForm.warehouseNumber) {
        let res = await getduoApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.cropType, cropQuality: this.ruleForm.cropQuality, wareId: this.ruleForm.warehouseId })
        this.duoList = filterSelect(res.data)
      }
    },
    // 选择垛号 修改回填
    async handlechangeDuoEdit() {
      this.ruleForm.warehouseId = this.wareList.find(item => item.label == this.ruleForm.warehouseNumber).value
      if (this.ruleForm.farmCode && this.ruleForm.teamCode && this.ruleForm.cropType && this.ruleForm.cropQuality && this.ruleForm.warehouseNumber) {
        let res = await getduoApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.cropType, cropQuality: this.ruleForm.cropQuality, wareId: this.ruleForm.warehouseId })
        this.duoList = filterSelect(res.data)
      }
    },
    // 毛重
    handleGW() {
      if (this.ruleForm.gw) {
        this.ruleForm.gw = (this.ruleForm.gw * 1).toFixed(2)
      }
      if (this.ruleForm.tare && (this.ruleForm.gw * 1) > (this.ruleForm.tare * 1)) {
        this.ruleForm.nw = (this.ruleForm.gw - this.ruleForm.tare).toFixed(2)
        this.netWeight = this.ruleForm.nw
        this.handleWater()
        this.handleMis()
      } else if (this.ruleForm.tare && (this.ruleForm.gw * 1) <= (this.ruleForm.tare * 1)) {
        Message({
          message: '毛重值应大于皮重值',
          type: 'error',
          duration: 3 * 1000
        })
        this.ruleForm.gw = ''
      }
    },
    // 皮重
    handleTARE() {
      if (this.ruleForm.tare) {
        this.ruleForm.tare = (this.ruleForm.tare * 1).toFixed(2)
      }
      if (this.ruleForm.gw && (this.ruleForm.gw * 1) > (this.ruleForm.tare * 1)) {
        this.ruleForm.nw = (this.ruleForm.gw - this.ruleForm.tare).toFixed(2)
        this.netWeight = this.ruleForm.nw
        this.handleWater()
        this.handleMis()
      } else if (this.ruleForm.tare && (this.ruleForm.gw * 1) <= (this.ruleForm.tare * 1)) {
        Message({
          message: '毛重值应大于皮重值',
          type: 'error',
          duration: 3 * 1000
        })
        this.ruleForm.tare = ''
      }
    },
    // 扣水
    handleWater() {
      this.waterWeight = (this.netWeight * ((this.ruleForm.waterRatio * 1) / 100)).toFixed(2)
      this.ruleForm.nw = (this.netWeight - (this.netWeight * ((this.ruleForm.waterRatio * 1) / 100)) - (this.netWeight * ((this.ruleForm.mixedRatio * 1) / 100))).toFixed(2)
    },
    // 扣杂
    handleMis() {
      this.mixedWeight = (this.netWeight * ((this.ruleForm.mixedRatio * 1) / 100)).toFixed(2)
      this.ruleForm.nw = (this.netWeight - (this.netWeight * ((this.ruleForm.waterRatio * 1) / 100)) - (this.netWeight * ((this.ruleForm.mixedRatio * 1) / 100))).toFixed(2)
    },
    // 新增弹框
    handleShowAddDialog(val) {
      if (val === 'carInfo') {
        this.$refs.CarInfo.handleGetInfo()
        this.$refs.CarInfo.handleGetSelect()
        this.carInfo = true
      }
      if (val === 'driverInfo') {
        this.$refs.DriverInfo.handleGetInfo()
        this.$refs.DriverInfo.handleGetSelect()
        this.driverInfo = true
      }
      if (val === 'betcarInfo') {
        this.$refs.BetcarInfo.handleGetInfo()
        this.betcarInfo = true
      }
      if (val === 'cropInfo') {
        this.$refs.CropInfo.handleGetInfo()
        this.cropInfo = true
      }
      if (val === 'cropVariety') {
        this.$refs.CropVariety.handleGetInfo()
        this.$refs.CropVariety.handleGetSelect()
        this.cropVariety = true
      }
      if (val === 'cropType') {
        this.$refs.CropType.handleGetInfo()
        this.cropType = true
      }
      if (val === 'waterStandard') {
        this.$refs.WaterStandard.handleGetInfo()
        this.$refs.WaterStandard.handleGetFarm()
        this.$refs.WaterStandard.handleGetSelect()
        this.waterStandard = true
      }
      if (val === 'impurityStandard') {
        this.$refs.ImpurityStandard.handleGetInfo()
        this.$refs.ImpurityStandard.handleGetFarm()
        this.$refs.ImpurityStandard.handleGetSelect()
        this.impurityStandard = true
      }
    },
    // 更新下拉框
    async handleRefreshList(val) {
      if (val === 'carInfo') {
        let res = await carinfoApi(this.$farmCode)
        this.carList = filterSelect(res.data)
      }
      if (val === 'driverInfo') {
        let res = await driverInfoApi(this.$farmCode)
        this.driverList = res.data
      }
      if (val === 'betcarInfo') {
        let res = await escortPersonApi(this.$farmCode)
        this.escortPersonList = res.data
      }
      if (val === 'cropInfo') {
        let res = await cropinfoSelectApi()
        this.cropinfoList = res.data
      }
      if (val === 'cropVariety') {
        if (!this.ruleForm.cropType) return
        let res = await cropTypeApi(this.ruleForm.cropType)
        this.cropVarietiesList = filterSelect(res.data)
      }
      if (val === 'cropType') {
        let res = await categorySelectApi()
        this.categoryList = filterSelect(res.data)
      }
      if (val === 'waterStandard') {

      }
      if (val === 'impurityStandard') {
      }
    }
  }
}
</script>

<style lang='scss' scoped>
.error-message {
  color: glay;
  font-size: 12px;
  margin-top: 5px;
}

.form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.el-form-item {
  width: 33%;
  // margin-bottom: 0;
}

.fir-title {
  margin-top: 0 !important;
}

.title {
  font-size: 17px !important;
  margin: 5px 0 !important;
}

.content {
  display: flex;
}

.button-box {
  margin-top: 60px;
}

.inStoragePCButton {
  width: 120px;
  height: 10vh;
  position: relative;
  float: left;
  background: #0e7b67;
  color: #fff;
  font-weight: 700;
  font-size: 1.2vw;
  line-height: 10vh;
  text-align: center;
  margin: 2vh 1vw;
  border-radius: 5px;
  cursor: pointer;
}

.dialog-footer {
  width: 180px;
  left: 50%;
  transform: translateX(-50%)
}


::v-deep .el-form-item__content {
  display: flex;
  align-items: center;
  height: 36px;
  line-height: 36px;
}

::v-deep .el-input {
  flex: 1;
  height: 36px;
}

::v-deep .el-select {
  flex: 1;
  height: 36px;
}

::v-deep .el-input__icon {
  line-height: 36px;
}

::v-deep .el-input__inner {
  height: 36px;
}
</style>
